/**   
* @Title: ContainmentContainer.java 
* @Package com.esun.util 
* @Description: TODO(计算一个view中可以承载子view的个数) 
* @author Miko baoz@500wan.com   
* @date 2011-1-17 上午11:51:52  
*/
package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk;

import com.esun.util.log.EDebug;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.LinearLayout;

/** 
 * @ClassName: ContainmentContainer 
 * @Description: TODO(计算一个view中可以承载子view的个数) 
 * @author Miko baoz@500wan.com
 * @date 2011-1-17 上午11:51:52 
 *  
 */
public class ContainmentCounter {
    
    
    
    /** 
    * @Title: getCount 
    * @Description: TODO(得到可以容纳的数量) 
    * @param father 父View
    * @param child 子View
    * @return int  可以容纳的数量
    */
    public static int getCount(View father,LinearLayout child, int picID , int marginLeft,int marginRight,int space){
        
        // 父View的宽度
        int fatherWide;
        
        // 子View的宽度
        int childWide;
        
        
//        Drawable drawable = father.getContext().getResources().getDrawable(picID);
        
        childWide = ((BitmapDrawable)father.getContext().getResources().getDrawable(picID)).getBitmap().getWidth();
        
        childWide = childWide + space;
        
        fatherWide = father.getWidth();
        
        if(fatherWide == 0){
        	DisplayMetrics dm;//屏幕分辨率容器

            dm = new DisplayMetrics();
            ((Activity) father.getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
            fatherWide = dm.widthPixels;
        }
        
        fatherWide = fatherWide - marginLeft - marginRight;
        EDebug.o(ContainmentCounter.class,"fatherWide is : " + fatherWide + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        
//        childWide = child.getWidth();
        EDebug.o(ContainmentCounter.class,"childWide is : " + childWide + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        
        return fatherWide / (childWide);
    }
    
}
